// index.ts
// 获取应用实例
import { OneNETAPI } from "../../utils/OneNETAPI/OneNETAPI"
const app = getApp<IAppOption>()
const OneNET = new OneNETAPI('sl5gkKWYKYCShqiS7egDu==pJ3c=')
Page({
  data: {
    //User:[{name:'----',Info:{HeartRate:'--',Spo2:'--',HighPres:'---',LowPres:'--'}}]
    User: [] as Array<any>
  },
  onShow() {
    let res: Array<any> = []
    OneNET.getDevices({
      device_id: [],
      successcb: (_res) => {
        _res = _res.data.devices
        for (let usr of _res) {
          console.log(usr)
          res.push({
            name: usr.title,
            id: usr.id,
            Info: {}
          })
        }
        for (let usr of res) {
          OneNET.getDataStreams({
            device_id: usr.id,
            successcb: (_res) => {
              _res = _res.data
              usr.Info = {
                HeartRate: _res[3].current_value,
                Spo2: _res[1].current_value,
                HighPres: _res[2].current_value,
                LowPres: _res[0].current_value,
              }
              this.setData({
                User: res
              })
              console.log(this.data.User)
            }
          })
        }
      }
    })

    //console.log(res)
  },
  UserTap(e: any) {
    app.globalData.UserId = e.currentTarget.id
    wx.navigateTo({
      url: '../chart/chart'
    })
  }
})
